<template>
	<view class="inventoryHistory">
		<!-- 时间选择 -->
		<view class="example-body">
			<uni-datetime-picker type="date" :value="nowTime" @change="rangeChange" />
		</view>
		<uni-table :border="false" stripe emptyText="暂无更多数据">
			<uni-tr>
				<uni-th>商品名称</uni-th>
				<uni-th>仓库名称</uni-th>
				<uni-th>仓库编码</uni-th>
				<uni-th>商品规格</uni-th>
				<uni-th>瓶盒条形码</uni-th>
				<uni-th>外箱条形码</uni-th>
				<uni-th>数量</uni-th>
			</uni-tr>
			<uni-tr v-for="(item,index) in list" :key="index">
				<uni-td>{{item.commodityName}}</uni-td>
				<uni-td>{{item.warehouseName}}</uni-td>
				<uni-td>{{item.warehouseCode}}</uni-td>
				<uni-td>{{item.commoditySpecification}}</uni-td>
				<uni-td>{{item.commodityVaseCode}}</uni-td>
				<uni-td>{{item.commodityCaseCode}}</uni-td>
				<uni-td>{{item.lastCount}}</uni-td>
			</uni-tr>
		</uni-table>
		<!-- 分页 -->
		<view class="pagination">
			<uni-pagination :current="page" show-icon="true" :total="total" @change="handlePageChange"></uni-pagination>
		</view>
	</view>
</template>

<script>
	export default {
		name: "inventoryHistory",
		data() {
			return {
				list: [],
				nowTime: "",
				page: 1,
				total: 0,
			}
		},
		onLoad() {
			let year = new Date().getFullYear()
			let mouth = new Date().getMonth() + 1
			let day = new Date().getDate()

			mouth = mouth >= 10 ? mouth : `0${mouth}`
			day = day >= 10 ? day : `0${day}`
			this.nowTime = `${year}-${mouth}-${day}`
		},
		onShow() {
			this.getInventoryHistory()
		},
		methods: {
			async getInventoryHistory() {
				try {
					const {
						data
					} = await this.request("getInventoryHistory", {
						phone: this.phone,
						page: this.page,
						date: this.nowTime,
					})

					this.list = data.data
					this.total = data.total
				} catch (e) {
					console.log(e)
				}
			},
			/* 分页 */
			handlePageChange(e) {
				this.page = e.current
				this.getOrderList()
			},
			rangeChange(range) {
				this.nowTime = range
				this.getInventoryHistory()
			}
		}
	}
</script>

<style lang="scss" scoped>
	.inventoryHistory {}
</style>
